import axios from 'axios';

// 创建 axios 实例的函数
function createAxiosInstance(baseURL) {
  const instance = axios.create({
    baseURL: baseURL,
    timeout: 5000,
  });

  // 请求拦截器
  instance.interceptors.request.use(
    config => {
      // 可以在这里添加请求头信息等
      return config;
    },
    error => {
      return Promise.reject(error);
    }
  );

  // 响应拦截器
  instance.interceptors.response.use(
    response => {
      return response.data;
    },
    error => {
      console.error('请求错误：', error);
      return Promise.reject(error);
    }
  );

  return instance;
}

const instance = createAxiosInstance('/api');
const getMd = createAxiosInstance('/md');

export default { instance, getMd };
